-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split Iterator into Iterator and IterableIterator in es6.d.ts #2083
Conversation
@@ -230,22 +230,22 @@ interface ArrayLike<T> { | |||
|
|||
interface Array<T> { | |||
/** Iterator */ | |||
[Symbol.iterator] (): Iterator<T>; | |||
[Symbol.iterator](): IterableIterator<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. It returns something htat is both an iterator, and something you can get an iterator off of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, all the built-in ES6 iterators are like that.
} | ||
|
||
interface Iterable<T> { | ||
[Symbol.iterator](): Iterator<T>; | ||
} | ||
|
||
interface IterableIterator<T> extends Iterable<T>, Iterator<T> { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to fix this because it's not deeply iterable, so it won't work if you do:
var iter: IterableIterator<any>;
iter[Symbol.iterator]()[Symbol.iterator]();
The type IterableIterator needs to be recursive for this to work.
Split Iterator into Iterator and IterableIterator in es6.d.ts
All the ES6 iterators are themselves iterable, namely they have a Symbol.iterator that returns an iterator. However, a user could define their own iterator and associated iterable, where the iterator does not have this method. To convey this, we need to use IterableIterator in es6.d.ts, but still leave Iterator so that user defined iterators can work.